package com.eportal.util;

import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.http.HttpSession;


public class VerifyCodeHelper {

	public static final String  FUNC_WALLET_ROLLOUT = "FUNC_WALLET_ROLLOUT";
	
	/**
	 * @param func 验证码是用在什么地方，比如：登录、支付等
	 * @param width 宽度
	 * @param height 高度
	 * @param session
	 * @param os 输出流
	 * @throws IOException
	 */
	public  static void createCode(String func,int width,int height,HttpSession session,OutputStream os) throws IOException{
		String code = VerifyCodeUtils.generateVerifyCode(4).toUpperCase();
		VerifyCodeUtils.outputImage(width, height, os,code);
		session.setAttribute("VerifyCode_"+func , code);
	}
	

	public static boolean  checkCode(HttpSession session,String func,String code){
		if(code!=null){
			code = code.toUpperCase();
		}
		String v = (String)session.getAttribute("VerifyCode_"+func);
		if(code!=null&&code.equals(v)){
			return true;
		}else{
			
		}
		return false;
	}
}
